package cn.sjtu.algorithm.greedy_algorithm.interval_union;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author syo 2319615164@qq.com
 * @description 区间合并算法
 * @date 2024/5/16
 * @Copyright syo
 */
// https://www.acwing.com/problem/content/805/
public class AcWing803 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] intervals = new int[n][2];
        for (int i = 0; i < n; i++) {
            intervals[i][0] = in.nextInt();
            intervals[i][1] = in.nextInt();
        }

        Arrays.sort(intervals, (x1, x2) -> x1[0] - x2[0]);
        int start = intervals[0][0];
        int end = intervals[0][1];
        int res = 1;
        for (int i = 1; i < n; i++) {
            if (intervals[i][0] <= end) {
                end = Math.max(intervals[i][1], end);
                continue;
            } else {
                res++;
                start = intervals[i][0];
                end = intervals[i][1];
            }
        }
        System.out.println(res);
    }
}
